﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

using AesApplication.Models;

namespace AesApplication.Controllers
{
    [Authorize]
    public class StoreManagerController : Controller
    {
        private AesContext db = new AesContext();

        //
        // GET: /StoreManager/
        public ActionResult Index()
        {
            StoreManagerIndexViewModel model = new StoreManagerIndexViewModel
            {
                Stores = db.StoresAssignedTo(WebSecurity.CurrentUserId)
            };

            return View(model);
        }


        [HttpPost]
        public ActionResult UpdateGrid(string submit, int[] AppCheckboxes)
        {
            if(AppCheckboxes != null)
            {
                if(submit.ToLower() == "deny")
                {
                    foreach(int appBox in AppCheckboxes)
                    {
                        Job job = db.Jobs.Find(appBox);
                        job.Status = JobStatus.Denied;
                    }
                    db.SaveChanges();
                }
                else if(submit.ToLower() == "approve")
                {
                    foreach (int appBox in AppCheckboxes)
                    {
                        Job job = db.Jobs.Find(appBox);
                        job.Status = JobStatus.Active;
                    }
                    db.SaveChanges();
                }
            }
            return RedirectToAction("Index", "StoreManager");
        }
	}
}